package collections;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CollMethod {
	public static void main(String[] args) {
		List list =new ArrayList<Animal>();
		list.add(new Animal("Tom1",12));
		list.add(new Animal("Tom2",13));
		list.add(new Animal("Tom3",12));
		list.add(new Animal("Tom4",15));
//		list.add("Tom1");
//		list.add("Tom4");
//		list.add("Tom3");
		p(list.toString());
		Collections.sort(list);
		p(list.toString());
		Collections.reverse(list);
		p(list.toString());
		Collections.shuffle(list);
		p(list.toString());
	}
    static void p(Object o){
    	System.out.println(o);
    }
}
class Animal implements Comparable<Animal>{
	String name;
	int    age;
	
	public Animal(String name, int age) {
		super();
		this.name = name;
		this.age = age;
	}
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return this.name;
	}
	@Override
	public int compareTo(Animal o) {
		// TODO Auto-generated method stub
		return o.name.compareTo(this.name);
	}
}